<script>
    $(function() {
        $('#folder_update_modal #repnum').rqDropDown({
            "datatype":"local",
            "source":get_repnums(),
            position:true
        }); 

		var currAP = '';
		var aps = [];
		aps.push(['','无保护策略']);
    	{% for ap in access_policy %}
    		if("{{ ap.id }}" == "{{ folder.access_policy_id }}") {
	        	currAP = "{{ ap.name }}";
	        }
	        var values = new Array();
	        values[0] = "{{ ap.id }}";
	        values[1] = "{{ ap.name }}";
	        aps.push(values);
    	{% endfor %}

    	$('#folder_ap_select').rqDropDown({
        	"datatype":"local",
        	"source":aps,
            position:true
    	}); 
    	$('#folder_ap_select').val(currAP);
        /* 为小图标绑定鼠标移入移出事件 */
        var obj = {
            'pool_name':'由1至32位小写英文字母、数字、中划线、冒号构成。'
        }
        bindMouseEvent('#folder_update_modal', obj);
        /* 为小图标绑定鼠标移入移出事件结束 */
	});
	var enable_submit = true;
	function submit_folder_update() {
		var load_name= $("#folder_update_modal").find("#load_this_name");
	    var access_policy= $("#folder_update_modal").find("#folder_ap_select");
	    var bValid = true;
    	bValid = bValid && checkNull(load_name, "请输入文件夹名称");
    	bValid = bValid && checkRegexp(load_name, /^[0-9a-z-:]{1,32}$/, "名称必须由1至32位小写英文字母、数字、中划线(英文)或冒号(英文)构成");

	    if (bValid) {
	        if(enable_submit) {
                enable_submit = false;
                var $submitBtn = $('.modal-footer').find('.btn-blue');
                $submitBtn.html('<i class="fa fa-spinner fa-spin" style="margin:3px 6px;"></i>');
                $('.rtn-tip').slideUp('fast');
                var folder_data = {
                    "folder_id":$.trim(load_name.attr('realvalue')),
                    "access_policy_id":$.trim(access_policy.attr('realvalue'))
                };
                $.post("/folder/update", folder_data,
                    function(data){
                        if (data.reply.is_success)
                        {
                            angular.element('#folder_controller').scope().close();
                            $('#volume_folder_tb').trigger("reloadGrid")
                        }else
                        {
                            error =  data.reply.error;
                            $('.rtn-tip').text(error).slideDown('fast');
                            $submitBtn.html(SelfTranslate("[[ 'label ok'|translate ]]"));
                            enable_submit = true;
                        }

                    });
            }

	    }
	}
</script>
<div class="modal-header">
    <h3>编辑</h3>
</div>

<div class="modal-body modal-body-height" id="folder_update_modal">
    <div class="pool-create-box">
        <div class="rtn-tip"></div>
        <table class="base-info">
            <tr>
                <td>
                    <label>名称</label><a>*</a>
                </td>
                <td colspan="3">
                    <input id="load_this_name" type="text" value="{{ folder.name }}" realvalue="{{ folder.id }}" readonly="readonly"/>
                    <i class="fa fa-question-circle" itype="pool_name"></i>
                </td>
            </tr>
            </tr>
                    <tr>
                        {% if not folder.ec_data %}
<!--
                        <td class="repnum">
                            <label>[['replication number'|translate]]</label>
                        </td>
                        <td class="repnum"><input id="repnum" readonly="readonly" class="rounded_dropdown" value='{{folder.repnum}}' realvalue="{{folder.repnum}}"/></td>
-->
    
                        {% else %}  
                        <td class="code_delete_op">
                            <label>[['replication number'|translate]]</label>
                        </td>
                        <td class="code_delete_op">
                                <input id="delete_code" style="width:40%;" readonly="readonly" value='{{folder.ec_data}}' realvalue="{{folder.ec_data}}"/>
                            <b>+</b>
                                <input  id="delete_code_r" style="width:40%;" readonly="readonly" class="rounded_dropdown" value='{{folder.ec_code}}' realvalue="{{folder.ec_data}}"/>
    
                        </td>
                        {% endif %}  
    
            </tr>

            <tr style='display:none'>
                <td>
                    <label>访问策略</label>
                </td>
                <td>
                    <input id="folder_ap_select" readonly="readonly" class="rounded_dropdown" value='' realvalue="{{ folder.access_policy_id|default ('', True)}}"/>
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
        </table>
    </div>
    <div class="error-tip">
        <p></p><span></span>
    </div>
    <div class="tip">
        <p></p><span></span>
    </div>
</div>
<div class="modal-footer">
    <button class="btn btn-blue" ng-click="update()">[[ 'label ok'|translate ]]</button>
    <button class="btn btn-white" ng-click="cancel()">[[ 'label cancel'|translate ]]</button>
</div>

